var t = getApp();

Page({
    data: {
        qrcode: "",
        posterList: [],
        current: 0
    },
    onLoad: function(t) {
        this.getPoster();
    },
    getPoster: function() {
        var e = this;
        t.util.request({
            url: "/commission/poster"
        }).then(function(t) {
            e.setData({
                qrcode: t.data.qrcode,
                posterList: t.data.posterList
            });
        });
    },
    swiperChange: function(t) {
        this.setData({
            current: t.detail.current
        });
    },
    saveImage: function() {
        var t = wx.createCanvasContext("poster"), e = this.posterList[this.current], s = this.qrcode, o = !1, a = !1;
        wx.showLoading({
            title: "生成中"
        }), wx.downloadFile({
            url: e.img,
            success: function(i) {
                t.drawImage(i.tempFilePath, 0, 0, 500, 750), o = !0, wx.downloadFile({
                    url: s,
                    success: function(s) {
                        t.drawImage(s.tempFilePath, e.hole.x, e.hole.y, e.hole.w, e.hole.h), a = !0;
                    }
                });
            }
        });
        var i = setInterval(function() {
            o && a && (clearInterval(i), t.draw(), wx.hideLoading(), setTimeout(function() {
                wx.canvasToTempFilePath({
                    canvasId: "poster",
                    destWidth: 500,
                    destHeight: 750,
                    quality: 1,
                    fileType: "jpg",
                    success: function(t) {
                        wx.saveImageToPhotosAlbum({
                            filePath: t.tempFilePath,
                            success: function() {
                                util.showSuccessToast("已保存到相册");
                            },
                            fail: function(t) {
                                console.log("error", t), util.showErrorToast("保存失败，请检查是否有保存到相册权限");
                            }
                        });
                    }
                });
            }, 300));
        }, 500);
    }
});